<?php

namespace app\validate\admin\students;

use app\model\Students;
use think\Validate;

class Edit extends Validate
{
    //数组顺序就是检测的顺序
    protected $rule = [
        'password' => 'confirm:re_password|min:6|max:30',
        'id_card' => 'require|idCard|checkIdCard:',
        'phone' => 'require|mobile|checkPhone:',
    ];

    //定义内置方法检验失败后返回的字符
    protected $message = [
		'password.confirm' => '两次密码输入不相同',
		'password.min' => '密码长度不能低于6个字符',
		'password.max' => '密码长度不能高于30个字符',
    ];

    protected function checkPhone($phone, $rule, $data){
        $studentId = Students::getFieldByPhone($phone,'id');
        if($studentId && $studentId != $data['id']){
            return '手机号已存在';
        }
        return true;
    }
    protected function checkIdCard($idCard, $rule, $data){
        $studentId = Students::getFieldByIdCard($idCard,'id');
        if($studentId && $studentId != $data['id']){
            return '身份证号码已存在';
        }
        return true;
    }
}